function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var e = t(require("../../../utils/util")), a = t(require("../../../utils/filter")), o = t(require("../../../api/api")), i = getApp();

Component({
    options: {
        multipleSlots: !0
    },
    properties: {
        modalParam: {
            type: Object
        },
        cancelText: {
            type: String,
            value: "不使用优惠券"
        },
        confirmText: {
            type: String,
            value: "使用优惠券"
        },
        modalName: {
            type: String
        }
    },
    data: {
        pageNum: 1,
        pageSize: 9,
        hasMore: !0,
        content_list: []
    },
    ready: function(t) {
        if (!this.selectComponent) throw new Error("小程序sdk暂不支持节点操作selectComponent");
        this.baseModal = this.selectComponent("#baseModal");
    },
    methods: {
        show: function() {
            this.baseModal.showModal(), this.fetchCouponList();
        },
        hide: function() {
            this.baseModal.hideModal();
        },
        fetchCouponList: function() {
            var t = this, e = this, a = {
                page: e.data.pageNum,
                available: 1,
                use_type: -1,
                page_size: 9
            };
            a = Object.assign(a, e.data.modalParam), o.default.couponList({
                data: a,
                success: function(e) {
                    var a = t, o = a.data.content_list;
                    if (e.data && e.data.data.coupon_list) {
                        1 == a.data.pageNum && (o = []);
                        var i = e.data.data.coupon_list;
                        i.forEach(t.mergeCouponHistoryInfo, t), i.length < a.data.pageSize ? t.setData({
                            content_list: o.concat(i),
                            hasMore: !1
                        }) : t.setData({
                            content_list: o.concat(i),
                            hasMore: !0,
                            pageNum: a.data.pageNum + 1
                        });
                    }
                }
            });
        },
        mergeCouponHistoryInfo: function(t) {
            t.start_date_format = e.default.formatCurrentDate(t.start_time), t.end_date_format = e.default.formatCurrentDate(t.end_time), 
            t.coupon_value_usd = t.voucher_value / 100, t.is_disabled = !(this.data.modalParam.itc >= t.use_limit_itc), 
            t.coupon_value_cny = a.default.convertCurrencyToCNY(t.voucher_value, i.globalData.currencyDatum);
        },
        onReachBottom: function(t) {
            var e = this;
            e.data.hasMore && e.fetchCouponList();
        },
        useThisCoupon: function(t) {
            var e = t.currentTarget.id;
            this.data.modalParam.itc >= this.data.content_list[e].use_limit_itc && (this.setData({
                activeIndex: t.currentTarget.id,
                selectedCoupon: this.data.content_list[e]
            }), this.triggerEvent("confirmEvent", {
                selectedCoupon: this.data.selectedCoupon
            }), this.hide());
        },
        _cancelModal: function() {
            this.hide(), this.setData({
                activeIndex: null,
                selectedCoupon: null
            }), this.triggerEvent("cancelEvent");
        },
        _confirmModal: function(t) {}
    }
});